<?php
    include('header.php');
    
    $sql = 'SELECT * FROM relate_article WHERE ra_id='.$_GET['ra_id'];
    $result = $db->Execute($sql);
    if($result->RecordCount()>0){
        
        if(img_exists(APPPATH.'/images/relate-article/'.$result->fields['ra_id'],$result->fields['ra_img'])){
            $img = '<img src="'.SITEURL.'/images/relate-article/'.$result->fields['ra_id'].'/'.$result->fields['ra_img'].'" /><input type="hidden" name="img_old" value="'.$result->fields['ra_img'].'" /><br />';
        }else{
            $img = '<input type="hidden" name="img_old" value="" />';
        }
	
	$ra_date = date('m/d/Y',$result->fields['ra_date']);
?>
    <div class="grid_24" id="contents">
        
        <div id="contents_">
            <form action="?m=relate-article&s=news-edit_query" method="post" enctype="multipart/form-data">
	    <div id="about_us_company_msg_1_en" class="form_field">
                <p>หัวข้อ : </p>
                <input type="text" name="news_title" class="input medium" value="<?php echo $result->fields['ra_title']; ?>" />
            </div>
            <div id="about_us_company_msg_1_en" class="form_field">
                <p>วันที่ : </p>
                <input type="text" name="news_date" class="input medium date_picker" value="<?php echo $ra_date; ?>" />
            </div>
            <div id="about_us_company_msg_1_en" class="form_field">
                <p>ข้อความ : </p>
                <textarea class="styled_textarea large height120" name="news_msg"><?php echo $result->fields['ra_msg']; ?></textarea>
            </div>
            <div id="about_us_company_msg_1_th" class="form_field">
                <p>รูปประกอบ : </p>
                <p class="guideline">ขนาด 254x134 pixel</p>
		<?php echo $img; ?>
                <input type="file" name="news_img" class="input large" />
            </div>
            
            <div id="about_us_company_msg_2_en" class="form_field">
		<input type="hidden" name="ra_id" value="<?php echo $result->fields['ra_id']; ?>" />
                <button class="button">SAVE</button>
                <!--<div class="button" onclick="window.location='?m=services&s=packing-dyntecdisc-product'">CANCEL</div>-->
            </div>
            </form>
        </div>
        
    </div><!-- end .grid_18 -->
    <div class="clear">&nbsp;</div>
<?php
    }else{
?>
    <div class="grid_24" id="contents">
        <div id="query_result">
        <?php
            echo 'ไม่มีข้อมูล <img src="images/ajax-loader.gif" />';
            redirect('?m=relate-article',3);
        ?>
        </div>
    </div><!-- end .grid_18 -->
    <div class="clear">&nbsp;</div>
<?php
    }
    include('footer.php');
?>
<script type="text/javascript">
    $(document).ready(function(){
        $('.date_picker').datepicker({
            'dateFormat':'mm/dd/yy',
            changeMonth: true,
	    changeYear: true
        }); 
    });
</script>